<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/14
 * Time: 17:39
 */
namespace App\Http\Controllers\Api\V1_6_6;

use App\Http\Requests\Api\V1_6_6\PersonalAccountWithdrawRequest;
use App\Services\PersonalAccountWithdrawService;
use App\Services\UserProfitService;
use Illuminate\Http\Request;

class PersonalAccountController extends BaseController
{
    protected $userProfitService;
    protected $personalAccountWithdrawService;

    public function __construct(UserProfitService $userProfitService, PersonalAccountWithdrawService $personalAccountWithdrawService)
    {
        parent::__construct();
        $this->userProfitService = $userProfitService;
        $this->personalAccountWithdrawService = $personalAccountWithdrawService;
    }

    /**
     * 账户余额
     */
    public function accountBalance()
    {
        return $this->userProfitService->accountProfit($this->user);
    }

    /**
     * 提现
     */
    public function withdraw(PersonalAccountWithdrawRequest $request)
    {
        return $this->personalAccountWithdrawService->withdraw($request, $this->user['user_id'], $this->user['realname']);
    }

    /**
     * 交易明细
     */
    public function tradeDetail(Request $request)
    {
        if (isset($request->status) && !empty($request->status)) {
            $status = $request->status;
        } else {
            $status = 0;
        }
        return $this->personalAccountWithdrawService->tradeDetail($this->user['user_id'], $status, $request->page);
    }

    /**
     * 收益明细
     */
    public function profitDetail(Request $request)
    {
        if (empty($request->type)) {
            return $this->responseJson(422);
        }
        return $this->userProfitService->profitDetail($this->user, $request->type);
    }
}